//
//  RepaymentDateView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/26.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class RepaymentDateView: UIView {
    
    fileprivate let bgView = UIView()
    fileprivate let imageView = UIImageView()
    fileprivate let tipLabel = UILabel()
    fileprivate let dateLabel = UILabel()
    let repaymentBtn = UIButton()

    init(model:InputBillModel) {
        super.init(frame: .zero)
        
        self.backgroundColor = UIColor.white
        
        self.addSubview(bgView)
        
        imageView.image = UIImage.init(named: "sound")
        bgView.addSubview(imageView)
        
        tipLabel.text = repaymentDate + ":"
        tipLabel.textAlignment = .center
        tipLabel.textColor = UIColor.gray
        tipLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        bgView.addSubview(tipLabel)
        
        dateLabel.text = model.repaymentDate
        dateLabel.textColor = UIColor.red
        dateLabel.textAlignment = .center
        dateLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        bgView.addSubview(dateLabel)
        
        repaymentBtn.setTitle(toRepayment+">", for: .normal)
        repaymentBtn.setTitleColor(UIColor.red, for: .normal)
        repaymentBtn.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.addSubview(repaymentBtn)
        
        if model.isPay == "1" {
            repaymentBtn.isHidden = true
        }
        
        let width = (tipLabel.text?.size(font: RATIO(maxNum: 16), height: RATIO_H(maxNum: 20)).width)! +  (dateLabel.text?.size(font: RATIO(maxNum: 16), height: RATIO_H(maxNum: 20)).width)!
        
        bgView.snp.makeConstraints { (make) in
            make.height.centerY.centerX.equalToSuperview()
            make.width.equalTo(width + RATIO(maxNum: 15))
        }
        
        imageView.snp.makeConstraints { (make) in
            make.centerY.left.equalToSuperview()
            make.width.height.equalTo(RATIO_H(maxNum: 15))
        }
        
        tipLabel.snp.makeConstraints { (make) in
            make.left.equalTo(imageView.snp.right)
            make.centerY.equalTo(imageView)
            make.height.equalTo(RATIO_H(maxNum: 20))
            make.width.equalTo((tipLabel.text?.size(font: RATIO(maxNum: 16), height: RATIO_H(maxNum: 20)).width)!)
        }
        
        dateLabel.snp.makeConstraints { (make) in
            make.left.equalTo(tipLabel.snp.right)
            make.centerY.height.equalTo(tipLabel)
            make.width.equalTo((dateLabel.text?.size(font: RATIO(maxNum: 16), height: RATIO_H(maxNum: 20)).width)!)
        }
        
        repaymentBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(RATIO(maxNum: -20))
            make.width.greaterThanOrEqualTo(10)
            make.height.greaterThanOrEqualTo(10)
            make.centerY.equalToSuperview()
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
